<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
<head>
	<meta charset="UTF-8">
    <title>修改用户信息</title>
    <%@ include file="head.jsp" %>
</head>
<body>
<div style="margin:10px;">

<form class="layui-form" action="">
	<div class="layui-form-item" style="visibility:hidden">
        <label class="layui-form-label">ID</label>
        <div class="layui-input-block">
            <input id="id" type="text" name="id" required  lay-verify="required" placeholder="请输用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input id="user_name" type="text" name="user_name" required  lay-verify="required" placeholder="请输用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input id="user_password" type="text" name="user_password" required  lay-verify="number" placeholder="用户密码" autocomplete="off" class="layui-input">
        </div>
    </div>
             
    <div id="deg_z" class="layui-form-item">
        <label class="layui-form-label">用户级别</label>
        <div class="layui-input-block">
            <input id="user_power" type="text" name="user_power" required  lay-verify="number" placeholder="请输入0或1" autocomplete="off" class="layui-input">
        </div>
    </div>
	<div class="layui-form-item">
	    <label class="layui-form-label">性别</label>
	    <div class="layui-input-block">
	      <input id="sexM" type="radio" name="sex" value="男" title="男">
	      <input id="sexW" type="radio" name="sex" value="女" title="女">
	    </div>
	</div>
    <div class="layui-form-item">
  			<label class="layui-form-label">生日</label>
                 <div class="layui-input-block">
	      	<input id="bir" class="layui-input" name="bir" placeholder="请选择日期" />
                 </div>
  	</div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="formDemo">确定</button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">重置</button>
        </div>
    </div>
</form>

</div>

<script>
    //Demo
    layui.use(['form','laydate'], function(){
    	 var form = layui.form;
         var $ = layui.$;
         var element = layui.element;
         var layer = layui.layer;
         var laydate = layui.laydate;
         
         var name = '${sessionScope.user_name}';
         var id = '${sessionScope.id}' ;
         var deg = '${sessionScope.deg}' ;
         var vs = '${sessionScope.vs}';
         alert("vs"+vs);
         var revise_id = '${sessionScope.revise_id}' ;
         //alert(revise_id) ;
         var user_mes=function(){
        	 
        	 $.ajax({
        		url:'selectById'
        		,data:{"id":revise_id}
        	 	,success:function(data){
        	 		//alert(data) ;
        	 		var json = JSON.parse(data);
        	 		$("#id").val(json[0].id);
        	 		$("#user_name").val(json[0].user_name) ;
        	 		$("#user_password").val(json[0].user_password) ;
        	 		$("#user_power").val(json[0].user_power) ;
        	 		if(json[0].sex == '男'){
        	 			
        	 			$("#sexM").attr('checked',true) ;
        	 		}else{
        	 			$("#sexW").attr('checked',true) ;
        	 		}
        	 		$("#bir").val(json[0].bir) ;
        	 		form.render(); 
        	 	}
        	 })
			if(deg != '0'){
			     $("#deg_z").hide();   		 
			}
         }
         //初始化表单
         user_mes();
         /* 显示当前时间函数  */
         function show(){
         	   var mydate = new Date();
         	   
         	   var str = "" + mydate.getFullYear() + "-";
         	   str += (mydate.getMonth()+1) + "-";
         	   str += mydate.getDate() ;
         	   return str;
         }
         
         /* 日期选择的初始化 */
         laydate.render({
  		    elem: '#bir'
  		    ,max: show()
  		    ,btns: ['clear','now', 'confirm']
  		});

         
         
         
        form.on('submit(formDemo)', function(data,index){
            var data1 = JSON.stringify(data.field);
			
            $.post("updateUser","data="+data1,function(msg){

				if(msg == "success"){
					if(vs == ''){
						parent.location.reload();
					}else{
						alert("修改成功！")
					}
				}
            });
			
            layer.close(index);
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index);

            
            return false;
        });
    });
</script>



</body>
</html>